
class Nexini
{
	iniHandle = null;
	iniFile = null;
	usingUTF = null;
	usingMK = null;
	usingML = null;
	
	constructor(file, useUTF8 = false, useMultiKey = false, useMultiLine = false)
	{
		this.open(file.tostring(), !!useUTF8, !!useMultiKey, !!useMultiLine);
	}
	
	function open(file, useUTF8 = false, useMultiKey = false, useMultiLine = false)
	{
		if(this.isActive()) return false;
		iniHandle = iniOpen(file.tostring(), !!useUTF8, !!useMultiKey, !!useMultiLine);
		iniFile = file.tostring();
		usingUTF = useUTF8;
		usingMK = useMultiKey;
		usingML = useMultiLine;
		return true;
	}
	
	function openx(file)
	{
		iniHandle = iniOpen(file.tostring(), usingUTF, usingMK, usingML);
		iniFile = file.tostring();
		return true;
	}
	
	function close(file)
	{
		if(this.isActive()) iniClose(iniHandle, file.tostring());
		iniHandle = null;
		return true;
	}
	
	function closex()
	{
		if(this.isActive()) iniClose(iniHandle, iniFile);
		iniHandle = null;
		return true;
	}
	
	function save()
	{
		if(!this.isActive()) return false;
		this.close(iniFile);
		this.openx(iniFile);
		return true;
	}
	
	function clear()
	{
		if(this.isActive()) this.close(iniFile);
		iniFile = null;
		usingUTF = null;
		usingMK = null;
		usingML = null;
		return true;
	}
	
	function modifyFile(newfile)
	{
		if(!this.isActive()) return false;
		this.close(newfile.tostring());
		iniFile = newfile.tostring();
		this.openx(iniFile);
		return true;
	}
	
	function modifyUTF8(useit = false)
	{
		usingUTF = !!useit;
		if(this.isActive())
		{
			this.close(iniFile);
			this.openx(iniFile);
		}
		return true;
	}
	
	function modifyMultiKey(useit = false)
	{
		usingMK = !!useit;
		if(this.isActive())
		{
			this.close(iniFile);
			this.openx(iniFile);
		}
		return true;
	}
	
	function modifyMultiLine(useit = false)
	{
		usingML = !!useit;
		if(this.isActive())
		{
			this.close(iniFile);
			this.openx(iniFile);
		}
		return true;
	}
	
	function isActive()
	{
		print("iniHandle type: "+typeof(iniHandle));
		if(typeof(iniHandle) != "userpointer") return false;
		return iniIsValid(iniHandle);
	}
	
	function isSection(name)
	{
		if(this.isActive())
		{
			return iniIsSection(iniHandle, name.tostring());
		}
		return false;
	}
	
	function hasMultipleValues(section, key)
	{
		if(this.isActive())
		{
			return iniIsMultiple(iniHandle, section.tostring(), key.tostring());
		}
		return false;
	}
	
	function getSections()
	{
		if(this.isActive())
		{
			return iniGetSections(iniHandle);
		}
		return false;
	}
	
	function getKeys(section)
	{
		if(this.isActive())
		{
			return iniGetKeys(iniHandle, section.tostring());
		}
		return false;
	}
	
	function getValues(section, key)
	{
		if(this.isActive())
		{
			return iniGetValues(iniHandle, section.tostring(), key.tostring());
		}
		return false;
	}
	
	function newSection(name, comment = ";", replace = false)
	{
		if(this.isActive())
		{
			return iniNewSection(iniHandle, name.tostring(), comment.tostring(), replace);
		}
		return false;
	}
	
	function dropSection(name)
	{
		if(this.isActive())
		{
			return iniDropSection(iniHandle, name.tostring());
		}
		return false;
	}
	
	function newKey(section, name)
	{
		if(this.isActive())
		{
			return iniNewKey(iniHandle, section.tostring(), name.tostring());
		}
		return false;
	}
	
	function dropKey(section, name)
	{
		if(this.isActive())
		{
			return iniDropKey(iniHandle, section.tostring(), name.tostring());
		}
		return false;
	}
	
	function setString(section, name, value, comment = ";", replace = false)
	{
		if(this.isActive())
		{
			return iniSetString(iniHandle, section.tostring(), name.tostring(), value.tostring(), comment.tostring(), replace);
		}
		return false;
	}
	
	function setNumeric(section, name, value, comment = ";", asHex = false, replace = false)
	{
		if(this.isActive())
		{
			return iniSetNumeric(iniHandle, section.tostring(), name.tostring(), value.tointeger(), comment.tostring(), asHex, replace);
		}
		return false;
	}
	
	function setFloat(section, name, value, comment = ";", replace = false)
	{
		if(this.isActive())
		{
			return iniSetFloat(iniHandle, section.tostring(), name.tostring(), value.tofloat(), comment.tostring(), replace);
		}
		return false;
	}
	
	function setBool(section, name, value, comment = ";", replace = false)
	{
		if(this.isActive())
		{
			return iniSetBool(iniHandle, section.tostring(), name.tostring(), !!value, comment.tostring(), replace);
		}
		return false;
	}
	
	function getString(section, name, default = "")
	{
		if(this.isActive())
		{
			return iniGetString(iniHandle, section.tostring(), name.tostring(), default.tostring());
		}
		return false;
	}
	
	function getNumeric(section, name, default = 0)
	{
		if(this.isActive())
		{
			return iniGetNumeric(iniHandle, section.tostring(), name.tostring(), default.tointeger());
		}
		return false;
	}
	
	function getFloat(section, name, default = 0.0)
	{
		if(this.isActive())
		{
			return iniGetFloat(iniHandle, section.tostring(), name.tostring(), default.tofloat());
		}
		return false;
	}
	
	function getBool(section, name, default = false)
	{
		if(this.isActive())
		{
			return iniGetBool(iniHandle, section.tostring(), name.tostring(), !!default);
		}
		return false;
	}
}
